﻿using System.Configuration;
using System.ServiceModel;
using Ninject;
using RentalOfCars.Client.Presentation;
using RentalOfCars.Client.WinformsClient;
using RentalOfCars.Server.Domain.ClientServerInterface;

namespace RentalOfCars.Client.Application
{
    internal class Program
    {
        public static void Main()
        {
            System.Windows.Forms.Application.EnableVisualStyles();

            var kernel = new StandardKernel();
            kernel.Bind<IAddClientWindowView>().To<AddClientWindow>();
            kernel.Bind<IAddCarWindowView>().To<AddCarWindow>();
            kernel.Bind<IAddEmployeeWindowView>().To<AddEmployeeWindow>();
            kernel.Bind<IMessenger>().To<Messenger>();

            string serverUri = ConfigurationManager.AppSettings.Get("ServerUri");
            var channelFactory = new ChannelFactory<IDbAccessSession>(new NetTcpBinding(),
                                                                      new EndpointAddress(serverUri));
            IDbAccessSession chanel = channelFactory.CreateChannel();

            var loginWindow = new LoginWindow();
            new LoginWindowPresenter(loginWindow, chanel, kernel);

            loginWindow.ShowDialog();

            if (loginWindow.Employee == null)
            {
                return;
            }

            var mainWindow = new MainWindow();
            new MainWindowPresenter(mainWindow, chanel, kernel);
            mainWindow.ShowDialog();

            chanel.Logoff();
        }
    }
}